//
//  UIImage+Circular.m
//  ShowYork
//
//  Created by hxh on 2021/5/13.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "UIImage+Circular.h"

@implementation UIImage (Circular)
-(UIImage *)imageWithCornerRadius:(CGFloat)radius {
    
    CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height);
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, UIScreen.mainScreen.scale);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor.clearColor CGColor]);
    CGContextFillRect(context, rect);
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    CGContextAddPath(context, [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
    CGContextClip(context);
    [self drawInRect:rect];
    UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
//
//    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
//    UIGraphicsBeginImageContextWithOptions(self.size, NO,UIScreen.mainScreen.scale);
//
//    CGContextAddPath(UIGraphicsGetCurrentContext(), [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
//    CGContextClip(UIGraphicsGetCurrentContext());
//
//    [self drawInRect:rect];
//    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    return image;
}

@end
